<?php

namespace App\Http\Common\pools\mysql;

use Illuminate\Database\Connection;
use Illuminate\Database\MySqlConnection;
use Swoole\ConnectionPool;

class MysqliConfigPool extends ConnectionPool
{
    public function __construct(string $db, int $size = self::DEFAULT_SIZE)
    {
        $config = config('database.connections.' . $db);
        $dsn = $config['driver'] . ':host=' . $config['host'] . ';dbname=' . $config['database'];
        parent::__construct(function () use($config, $dsn) {
            $pdo = new \PDO($dsn, $config['username'], $config['password']);
            return new MySqlConnection($pdo);
        }, $size);
    }

    public function put($connection): void
    {
        parent::put($connection);
    }

    public function get(): Connection
    {
        return parent::get(); // TODO: Change the autogenerated stub
    }
}
